package com.hyts.mvc.loader.item;

import com.hyts.mvc.annotation.MvcBootApplication;
import com.hyts.mvc.bean.MvcConfigBean;
import com.hyts.mvc.config.ViewType;
import com.hyts.mvc.context.WebMvcContext;
import com.hyts.mvc.loader.WebMvcConfigLoader;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.mvc.loader.item
 * author:Libo/Alex
 * create-date:2019-07-01 11:00
 * email:liboware@gmail.com
 * description:此类主要用于:
 * @author alex
 */
public class WebMvcAnnotationConfigLoader extends WebMvcConfigLoader<MvcBootApplication>{

    /**
     * 读取配置mvc总体核心转发配置
     * @param param
     * @return
     */
    @Override
    public MvcConfigBean load(MvcBootApplication param, MvcConfigBean configBean) {
        return  MvcConfigBean.builder()
                .prefixPath(param.prefixPath())
                .subfixPath(param.subfixPath())
                .scanPackage(ArrayUtils.isEmpty(param.basePackages())?
                        new String[]{WebMvcContext.getBootstrapMainClass().
                        getPackage().getName()}:param.basePackages())
                .urlPath(param.urlPath())
                .prefixPath(StringUtils.defaultIfEmpty(param.prefixPath(),configBean.getPrefixPath() ))
                .subfixPath(StringUtils.defaultIfEmpty(param.subfixPath(),configBean.getSubfixPath()))
                .scanPackage(ArrayUtils.isEmpty(param.basePackages())?new String[]{WebMvcContext.getBootstrapMainClass().getPackage().getName()}:param.basePackages())
                .urlPath(StringUtils.defaultIfEmpty(param.urlPath(),configBean.getUrlPath()))
                .viewType(ViewType.THYMELEAF).build();
    }

    @Override
    public int order() {
        return 4;
    }
}
